package com.carp.springframework.beans.factory.config;

import com.carp.springframework.beans.PropertyValues;
import lombok.Getter;

import java.util.Optional;

/**
 * @author lile
 * @date 2023/2/2
 */
@Getter
public class BeanDefinition {

    private final Class<?> beanClass;
    private final PropertyValues propertyValues;
    private String initMethodName;
    private String destroyMethodName;
    private String scope = ConfigurableBeanFactory.SCOPE_SINGLETON;
    private boolean singleton = true;
    private boolean prototype = false;

    public BeanDefinition(Class<?> beanClass) {
        this.beanClass = beanClass;
        this.propertyValues = new PropertyValues();
    }

    public BeanDefinition(Class<?> beanClass, PropertyValues propertyValues) {
        this.beanClass = beanClass;
        this.propertyValues = Optional.ofNullable(propertyValues).orElse(new PropertyValues());
    }

    public void setScope(String scope) {
        this.scope = scope;
        this.singleton = ConfigurableBeanFactory.SCOPE_SINGLETON.equals(scope);
        this.prototype = ConfigurableBeanFactory.SCOPE_PROTOTYPE.equals(scope);
    }


    public void setInitMethodName(String initMethodName) {
        this.initMethodName = initMethodName;
    }

    public void setDestroyMethodName(String destroyMethodName) {
        this.destroyMethodName = destroyMethodName;
    }

}
